<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {include file="/layout/scriptload"}
    <title>公众号粉丝查重</title>
    <style>
        .qrcode{
            padding: 5px;background: #f4f4f4;border: 1px solid #dddddd;cursor: pointer;margin-left: 5px;
        }
    </style>
</head>
<body>
<div class="box">
    <section class="content-header">
        <ol class="breadcrumb">
            <li><a><i class="fa fa-dashboard"></i> 微信粉丝管理</a></li>
            <li class="active">公众号粉丝查重</li>
        </ol>
    </section>
    <!-- /.box-header -->
    <section class="content">
    <div class="box-body">
        <div id="example1_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
            <div class="row">
                <div class="col-sm-12">
                        <div id="example1_filter" class="dataTables_length">
                            <label>
                                <input type="search" id="keyword" class="form-control input-sm" placeholder="原始ID丶公众号" aria-controls="example1">
                            </label>
                            <button type="button" id="search" class="btn margin" style="background: #18bc9c;color: #ffffff;">搜索</button>
                            <button type="button" onclick="relist()" title="刷新" class="btn bg-aqua margin"><i class="fa fa-refresh"></i></button>
                            <button type="button" onclick="toCheck()" class="btn margin" style="background: #18bc9c;color: #ffffff;"> 添加查重任务</button>
                            <button type="button" onclick="todelete()" class="btn bg-red margin"><i class="fa  fa-trash-o"></i> 删除</button>
                            <button type="button" id="excel" class="btn margin" style="background: #18bc9c;color: #ffffff;"><i class="fa fa-download"></i> 导出查重数据</button>
                            <button type="button" id="exce2" class="btn margin" style="background: #18bc9c;color: #ffffff;"><i class="fa fa-upload"></i> 导入ghid</button>
                            <button type="button" onclick="toAll()" class="btn bg-aqua margin" >全部查重</button>
                        </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <table id="example1" class="table table-bordered table-striped dataTable" role="grid" aria-describedby="example1_info">
                        <thead>
                        <tr role="row">
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 60px;">
                                <input id="allchecked" type="checkbox" value="" style="margin-left: 10px">
                            </th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 180px;">原始ID1</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 180px;">公众号1</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 250px;">公众号1粉丝数量</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px;">原始ID2</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px;">公众号2</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 250px;">公众号2粉丝数量</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 250px;">粉丝重复数量</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 200px">重复百分比</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 250px">创建时间</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px">状态</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px">操作</th>
                        </tr>
                        </thead>
                        <tbody id="tb">
                        </tbody>
                    </table>
                    <div class="layui-row pull-right" id="footpager" align="center"></div>
                </div>
            </div>
        </div>
    </div>
    <!-- /.box-body -->
    </section>
</div>
</body>
<script>
    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#exce2' //绑定元素
            ,accept:'file'
            ,exts:'xlsx'
            ,auto:true
            ,url: '{:url("admin/Adminindex/uploadGhid")}' //上传接口
            , before: function (input) {
                loading = layer.load(2, {
                    shade: [0.2, '#000']
                });
            }
            ,done: function(res){
                layer.close(loading);
                if(res.code == 0){
                    layerAlert(res.msg,function(){
                        table.destroy();
                        getlist(_keyword);
                    });
                }else{
                    ayerAlert(res.msg);
                }
            }
            ,error: function(){
                layerAlert('系统出错，请联系管理员');
            }
        });
    });
    var _keyword = '';
    var _page='1';
    var _size='10';
    $(function(){
        getlist(_keyword);
        $('#search').click(function(){
            _page = 1;
            table.destroy();
            var keyword = $('#keyword').val();
            getlist(keyword);
        });
        //反选
        $('#allchecked').click(function(){
            $("[name = checkboxed]:checkbox").each(function () {
                $(this).prop("checked", !$(this).prop("checked"));
            });
        });
        //导出
        $('#excel').click(function(){
            var url =  '{:url("admin/Adminindex/downFansExcel")}';
            window.location.href= url;
        });
    });
    function getlist(_keyword)
    {
        $.ajax({
            type: 'post',
            cache: false,
            url:'{:url("admin/Fans/getRepetList")}',
            data: {keyword:_keyword,page:_page,size:_size},
            success: function(data) {
                if(data.code=="0")
                {
                    $("#tb tr").remove();
                    $.each(data.info,function(index,item){
                        var html='<tr role="row" class="odd" id="tr_'+item.id+'">';
                        html+='<td style="vertical-align: middle;"><input name="checkboxed" value="'+item.id+'" type="checkbox" style="margin-left: 10px"></td>';
                        html+='<td style="vertical-align: middle;">'+item.ghid_1+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.name_1+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.fanstotal1+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.ghid_2+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.name_2+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.fanstotal2+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.repet_fans_total+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.repetrate+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.createtime+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.statusname+'</td>';
                        html+='<td style="vertical-align: middle;text-align: center">';
                        html+='<div class="btn-group">';
                        if(item.status== 1)
                            html+=' <button type="button" class="btn todo" ghid1="'+item.ghid_1+'" ghid2="'+item.ghid_2+'" style="background: #18bc9c;color: #ffffff;">查重</button>';
                        else
                            html+=' <button disabled type="button" class="btn" style="background: #18bc9c;color: #ffffff;">查重</button>';
                        html+='</div>';
                        html+='</td>';
                        html+='</tr>';
                        $("#tb").append(html);
                    });
                    $('.todo').click(function(){
                        var $_this = $(this);
                        var _ghid1 = $_this.attr('ghid1');
                        var _ghid2 = $_this.attr('ghid2');
                        $.ajax({
                            url:'{:url("admin/fans/contrastInfo2")}',
                            cache: false,
                            data:{ghid1:_ghid1,ghid2:_ghid2},
                            type:'post',
                            success:function(data){
                                if(data.code == 0){
                                    layerAlert(data.msg,function(){
                                        relist();
                                    })
                                }else{
                                    layerAlert(data.msg);
                                }
                            }
                        })
                    })
                    table = $('#example1').DataTable({
                        "paging": false,
                        "searching": false,
                        "info": false,
                        "autoWidth": true,
                    });
                    layerPager(_page,_size,data.count,"footpager","footpagerbind");
                }
            },
            error: function() {
                alert("发生系统错误,请与管理员联系！");
            }
        });
    }
    function footpagerbind(cpage)
    {
        _page=cpage;
        table.destroy();
        getlist();
    }
    function toCheck(){
        url = "{:url('fans/duplicateCheck')}";
        layerWindow('公众号粉丝管理->粉丝查重',url,'50%','70%');
    }
    //执行全部查重
    function toAll()
    {
        layerConfirm('是否执行',function () {
            $.ajax({
                url:'{:url("admin/fans/contrastInfo3")}',
                cache: false,
                data:{},
                type:'post',
                beforeSend:function(index){
                    loading = layer.load(2, {
                        shade: [0.2, '#000']
                    });
                },
                success:function(data){
                    if(data.code == 0){
                        layerAlert(data.msg,function(){
                            relist();
                        })
                    }else{
                        layerAlert(data.msg);
                    }
                },
                complete:function(index){
                    layer.close(loading);
                }
            })
        });
    }
    function todelete(){
        var _ids =[];
        $('input[name="checkboxed"]:checked').each(function(){
            _ids.push($(this).val());
        });
        if(_ids == ''){
            layerAlert('请选择要删除的数据');
            return false;
        }
        url = "{:url('admin/Fans/delFansRepet')}";
        $.ajax({
            url:url,
            cache: false,
            data:{id:_ids},
            type:'post',
            success:function(data){
                if(data.code == 0){
                    layerAlert('删除成功',function(){
                        relist();
                    })
                }else{
                    layerAlert('删除失败');
                }
            }
        })
    }
    function relist() {
        table.destroy();
        getlist(_keyword);
    }
</script>
</html>